home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MOR55SRC.ZIP / MORIA / SOURCE / WANDS.C < prev    next >
C/C++ Source or Header  |  1992-12-07  |  5KB  |  194 lines

  1. /* source/wands.c: wand code
  2.  
  3.    Copyright (c) 1989-92 James E. Wilson, Robert A. Koeneke
  4.  
  5.    This software may be copied and distributed for educational, research, and
  6.    not for profit purposes provided that this copyright and statement are
  7.    included in all such copies. */
  8.  
  9. #include "config.h"
  10. #include "constant.h"
  11. #include "types.h"
  12. #include "externs.h"
  13.  
  14. #ifdef USG
  15. #ifndef ATARIST_MWC
  16. #include <string.h>
  17. #endif
  18. #else
  19. #include <strings.h>
  20. #endif
  21.  
  22. /* Wands for the aiming.                */
  23. void aim()
  24. {
  25.   int32u i;
  26.   register int l, ident;
  27.   int item_val, j, k, chance, dir;
  28.   register inven_type *i_ptr;
  29.   register struct misc *m_ptr;
  30.  
  31.   free_turn_flag = TRUE;
  32.   if (inven_ctr == 0)
  33.     msg_print("But you are not carrying anything.");
  34.   else if (!find_range(TV_WAND, TV_NEVER, &j, &k))
  35.     msg_print("You are not carrying any wands.");
  36.   else if (get_item(&item_val, "Aim which wand?", j, k, CNIL, CNIL))
  37.     {
  38.       i_ptr = &inventory[item_val];
  39.       free_turn_flag = FALSE;
  40.       if (get_dir(CNIL, &dir))
  41.     {
  42.       if (py.flags.confused > 0)
  43.         {
  44.           msg_print("You are confused.");
  45.           do
  46.         {
  47.           dir = randint(9);
  48.         }
  49.           while (dir == 5);
  50.         }
  51.       ident = FALSE;
  52.       m_ptr = &py.misc;
  53.       chance = m_ptr->save + stat_adj(A_INT) - (int)i_ptr->level
  54.         + (class_level_adj[m_ptr->pclass][CLA_DEVICE] * m_ptr->lev / 3);
  55.       if (py.flags.confused > 0)
  56.         chance = chance / 2;
  57.       if ((chance < USE_DEVICE) && (randint(USE_DEVICE - chance + 1) == 1))
  58.         chance = USE_DEVICE; /* Give everyone a slight chance */
  59.       if (chance <= 0)  chance = 1;
  60.       if (randint(chance) < USE_DEVICE)
  61.         msg_print("You failed to use the wand properly.");
  62.       else if (i_ptr->p1 > 0)
  63.         {
  64.           i = i_ptr->flags;
  65.           (i_ptr->p1)--;
  66.           while (i != 0)
  67.         {
  68.           j = bit_pos(&i) + 1;
  69.           k = char_row;
  70.           l = char_col;
  71.           /* Wands             */
  72.           switch(j)
  73.             {
  74.             case 1:
  75.               msg_print("A line of blue shimmering light appears.");
  76.               light_line(dir, char_row, char_col);
  77.               ident = TRUE;
  78.               break;
  79.             case 2:
  80.               fire_bolt(GF_LIGHTNING, dir, k, l, damroll(4, 8),
  81.                 spell_names[8]);
  82.               ident = TRUE;
  83.               break;
  84.             case 3:
  85.               fire_bolt(GF_FROST, dir, k, l, damroll(6, 8),
  86.                 spell_names[14]);
  87.               ident = TRUE;
  88.               break;
  89.             case 4:
  90.               fire_bolt(GF_FIRE, dir, k, l, damroll(9, 8),
  91.                 spell_names[22]);
  92.               ident = TRUE;
  93.               break;
  94.             case 5:
  95.               ident = wall_to_mud(dir, k, l);
  96.               break;
  97.             case 6:
  98.               ident = poly_monster(dir, k, l);
  99.               break;
  100.             case 7:
  101.               ident = hp_monster(dir, k, l, -damroll(4, 6));
  102.               break;
  103.             case 8:
  104.               ident = speed_monster(dir, k, l, 1);
  105.               break;
  106.             case 9:
  107.               ident = speed_monster(dir, k, l, -1);
  108.               break;
  109.             case 10:
  110.               ident = confuse_monster(dir, k, l);
  111.               break;
  112.             case 11:
  113.               ident = sleep_monster(dir, k, l);
  114.               break;
  115.             case 12:
  116.               ident = drain_life(dir, k, l);
  117.               break;
  118.             case 13:
  119.               ident = td_destroy2(dir, k, l);
  120.               break;
  121.             case 14:
  122.               fire_bolt(GF_MAGIC_MISSILE, dir, k, l, damroll(2, 6),
  123.                 spell_names[0]);
  124.               ident = TRUE;
  125.               break;
  126.             case 15:
  127.               ident = build_wall(dir, k, l);
  128.               break;
  129.             case 16:
  130.               ident = clone_monster(dir, k, l);
  131.               break;
  132.             case 17:
  133.               ident = teleport_monster(dir, k, l);
  134.               break;
  135.             case 18:
  136.               ident = disarm_all(dir, k, l);
  137.               break;
  138.             case 19:
  139.               fire_ball(GF_LIGHTNING, dir, k, l, 32, "Lightning Ball");
  140.               ident = TRUE;
  141.               break;
  142.             case 20:
  143.               fire_ball(GF_FROST, dir, k, l, 48, "Cold Ball");
  144.               ident = TRUE;
  145.               break;
  146.             case 21:
  147.               fire_ball(GF_FIRE, dir, k, l, 72, spell_names[28]);
  148.               ident = TRUE;
  149.               break;
  150.             case 22:
  151.               fire_ball(GF_POISON_GAS, dir, k, l, 12, spell_names[6]);
  152.               ident = TRUE;
  153.               break;
  154.             case 23:
  155.               fire_ball(GF_ACID, dir, k, l, 60, "Acid Ball");
  156.               ident = TRUE;
  157.               break;
  158.             case 24:
  159.               i = 1L << (randint(23) - 1);
  160.               break;
  161.             default:
  162.               msg_print("Internal error in wands()");
  163.               break;
  164.             }
  165.           /* End of Wands.            */
  166.         }
  167.           if (ident)
  168.         {
  169.           if (!known1_p(i_ptr))
  170.             {
  171.               m_ptr = &py.misc;
  172.               /* round half-way case up */
  173.               m_ptr->exp += (i_ptr->level +(m_ptr->lev >> 1)) /
  174.             m_ptr->lev;
  175.               prt_experience();
  176.  
  177.               identify(&item_val);
  178.               i_ptr = &inventory[item_val];
  179.             }
  180.         }
  181.           else if (!known1_p(i_ptr))
  182.         sample (i_ptr);
  183.           desc_charges(item_val);
  184.         }
  185.       else
  186.         {
  187.           msg_print("The wand has no charges left.");
  188.           if (!known2_p(i_ptr))
  189.         add_inscribe(i_ptr, ID_EMPTY);
  190.         }
  191.     }
  192.     }
  193. }
  194.